{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "# 1、create  列表\n",
    "# faceListId\n",
    "faceListId =\"zy03\"\n",
    "create_facelists_url = \"https://api-zy.cognitiveservices.azure.com/face/v1.0/facelists/{}\"\n",
    "subscription_key = \"e86d9bb9e8d942ca94b739af0306ef94\"\n",
    "assert subscription_key\n",
    "\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "data = {\n",
    "    \"name\":\"相册集\",\n",
    "    \"userDate\":\"11人,10男,1女\",\n",
    "   \"recognitionModel\":\"recognition_03\",\n",
    "    \n",
    "}\n",
    "\n",
    "r_create = requests.put(create_facelists_url.format(faceListId),headers=headers,json=data) \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b''"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_create.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2、Add face\n",
    "add_face_url = \"https://api-zy.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedFaces\"\n",
    "subscription_key = \"e86d9bb9e8d942ca94b739af0306ef94\"\n",
    "assert subscription_key\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "img_url = \"https://wx3.sinaimg.cn/mw690/ed4d61ably1ge90p0nsoqj20u011i439.jpg\"\n",
    "\n",
    "params_add_face={\n",
    "    \"userData\":\"Tay\"\n",
    "}\n",
    "\n",
    "r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={\"url\":img_url})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_add_face.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 封装成函数方便添加图片\n",
    "def AddFace(img_url=str,userData=str):\n",
    "    add_face_url =\"https://api-zy.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedFaces\"\n",
    "    assert subscription_key\n",
    "    headers = {\n",
    "        # Request headers\n",
    "        'Content-Type': 'application/json',\n",
    "        'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "    }\n",
    "    img_url = img_url\n",
    "\n",
    "    params_add_face={\n",
    "        \"userData\":userData\n",
    "    }\n",
    "    r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "    return r_add_face.status_code#返回出状态码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"https://wx2.sinaimg.cn/mw690/006UkIMQgy1gilovpedhzj30u011ijv3.jpg\",\"Lauv\")\n",
    "AddFace(\"https://wx2.sinaimg.cn/mw690/ecff9b1aly1gh1xv6j4lcj20u011h44a.jpg\",\"Blackbear\")\n",
    "AddFace(\"https://ww4.sinaimg.cn/bmiddle/99a80fedly1gk0a5bswkzj20u011htcc.jpg\",\"PostMalone\")\n",
    "AddFace(\"https://ww4.sinaimg.cn/bmiddle/e9281103ly1gjs2pqttj2j20u011idmr.jpg\",\"ConanGray\")\n",
    "AddFace(\"https://wx3.sinaimg.cn/mw690/006ST4imgy1gjzivxp70oj30to0jsdit.jpg\",\"MGK\")\n",
    "AddFace(\"https://ww3.sinaimg.cn/bmiddle/005KrlAhly1ggue5t1klyj30u018pn6u.jpg\",\"Logic\")\n",
    "AddFace(\"https://ww2.sinaimg.cn/bmiddle/bf26cc17ly1gjj048l7dej20v912ok93.jpg\",\"lany\")\n",
    "AddFace(\"https://wx4.sinaimg.cn/mw690/005QABcggy1ghqiu30pkyj30ld0fdtb0.jpg\",\"LewisCapaldi\")\n",
    "AddFace(\"https://wx3.sinaimg.cn/mw690/005Rug7vly1gf6tp1c2s9j30u011in32.jpg\",\"Christopher\")\n",
    "AddFace(\"https://wx2.sinaimg.cn/mw690/007Su2Scly1gjuky00vvyj30u011hqix.jpg\",\"JB\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaces': [{'persistedFaceId': '4f7d29aa-3328-4db4-aa99-078ca099f06b',\n",
       "   'userData': 'Tay'},\n",
       "  {'persistedFaceId': 'c0369103-92a9-45da-9360-1032217e2a58',\n",
       "   'userData': 'Blackbear'},\n",
       "  {'persistedFaceId': 'cdab2d9e-a699-4ea8-bfea-f055b9e59efa',\n",
       "   'userData': 'PostMalone'},\n",
       "  {'persistedFaceId': '5183429e-0f90-4f75-8b8a-e75e497f68ef',\n",
       "   'userData': 'ConanGray'},\n",
       "  {'persistedFaceId': '217752cd-2fb2-4f91-a454-8286f9cbb872',\n",
       "   'userData': 'Logic'},\n",
       "  {'persistedFaceId': 'e65041fc-42c4-4f9c-bfa5-964088a7e432',\n",
       "   'userData': 'lany'},\n",
       "  {'persistedFaceId': '00608469-807f-46a5-a203-11610c8944f8',\n",
       "   'userData': 'LewisCapaldi'},\n",
       "  {'persistedFaceId': '27dcf411-1e11-410c-b3a7-755d38ddc758',\n",
       "   'userData': 'Christopher'},\n",
       "  {'persistedFaceId': '3ae39d18-995e-4d3a-ad92-5bddf521d183',\n",
       "   'userData': 'JB'},\n",
       "  {'persistedFaceId': '7b982ff5-cf29-432b-863d-8aa70758eeed',\n",
       "   'userData': 'Blackbear'},\n",
       "  {'persistedFaceId': 'ef692497-e61f-4302-895d-43d850aa12ca',\n",
       "   'userData': 'PostMalone'},\n",
       "  {'persistedFaceId': 'fc594817-b796-458e-86d8-a7aa0171d75c',\n",
       "   'userData': 'ConanGray'},\n",
       "  {'persistedFaceId': 'b0d27b78-2b7e-449a-af9c-a6b906c647fb',\n",
       "   'userData': 'Logic'},\n",
       "  {'persistedFaceId': 'd54ae7ec-858c-4c61-88f3-2086c603e13b',\n",
       "   'userData': 'lany'},\n",
       "  {'persistedFaceId': '4b9d6a82-8dee-46f0-8ddb-aa58c86019d2',\n",
       "   'userData': 'LewisCapaldi'},\n",
       "  {'persistedFaceId': '5d0fd1d0-1130-47e8-a91b-0200e34545c1',\n",
       "   'userData': 'Christopher'},\n",
       "  {'persistedFaceId': 'ce6e1f1b-1011-4cdc-bb62-c261ea34ea28',\n",
       "   'userData': 'JB'}],\n",
       " 'faceListId': 'zy03',\n",
       " 'name': '相册集'}"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Get facelist\n",
    "get_facelist_url = \"https://api-zy.cognitiveservices.azure.com/face/v1.0/facelists/zy03\"\n",
    "r_get_facelist = requests.get(get_facelist_url,headers=headers)#学生填写\n",
    "r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'persistedFaceId': '4f7d29aa-3328-4db4-aa99-078ca099f06b',\n",
       "  'userData': 'Tay'},\n",
       " {'persistedFaceId': 'c0369103-92a9-45da-9360-1032217e2a58',\n",
       "  'userData': 'Blackbear'},\n",
       " {'persistedFaceId': 'cdab2d9e-a699-4ea8-bfea-f055b9e59efa',\n",
       "  'userData': 'PostMalone'},\n",
       " {'persistedFaceId': '5183429e-0f90-4f75-8b8a-e75e497f68ef',\n",
       "  'userData': 'ConanGray'},\n",
       " {'persistedFaceId': '217752cd-2fb2-4f91-a454-8286f9cbb872',\n",
       "  'userData': 'Logic'},\n",
       " {'persistedFaceId': 'e65041fc-42c4-4f9c-bfa5-964088a7e432',\n",
       "  'userData': 'lany'},\n",
       " {'persistedFaceId': '00608469-807f-46a5-a203-11610c8944f8',\n",
       "  'userData': 'LewisCapaldi'},\n",
       " {'persistedFaceId': '27dcf411-1e11-410c-b3a7-755d38ddc758',\n",
       "  'userData': 'Christopher'},\n",
       " {'persistedFaceId': '3ae39d18-995e-4d3a-ad92-5bddf521d183', 'userData': 'JB'},\n",
       " {'persistedFaceId': '7b982ff5-cf29-432b-863d-8aa70758eeed',\n",
       "  'userData': 'Blackbear'},\n",
       " {'persistedFaceId': 'ef692497-e61f-4302-895d-43d850aa12ca',\n",
       "  'userData': 'PostMalone'},\n",
       " {'persistedFaceId': 'fc594817-b796-458e-86d8-a7aa0171d75c',\n",
       "  'userData': 'ConanGray'},\n",
       " {'persistedFaceId': 'b0d27b78-2b7e-449a-af9c-a6b906c647fb',\n",
       "  'userData': 'Logic'},\n",
       " {'persistedFaceId': 'd54ae7ec-858c-4c61-88f3-2086c603e13b',\n",
       "  'userData': 'lany'},\n",
       " {'persistedFaceId': '4b9d6a82-8dee-46f0-8ddb-aa58c86019d2',\n",
       "  'userData': 'LewisCapaldi'},\n",
       " {'persistedFaceId': '5d0fd1d0-1130-47e8-a91b-0200e34545c1',\n",
       "  'userData': 'Christopher'},\n",
       " {'persistedFaceId': 'ce6e1f1b-1011-4cdc-bb62-c261ea34ea28', 'userData': 'JB'}]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "faceId = r_get_facelist.json()['persistedFaces']\n",
    "faceId"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Detect face 删除列表内人脸id\n",
    "faceListId =\"zy03\"\n",
    "delete_face_url =\"https://api-zy.cognitiveservices.azure.com//face/v1.0/facelists/{}/persistedfaces/{}\"\n",
    "\n",
    "assert subscription_key\n",
    "\n",
    "persistedFaceId ='ce6e1f1b-1011-4cdc-bb62-c261ea34ea28'\n",
    "# 直接取上面获得的ID{'persistedFaceId': 'f18450d3-60d2-45f3-a69e-783574dc3ce8'} \n",
    "\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "\n",
    "# 注意requests请求为delete\n",
    "r_delete_face = requests.delete(delete_face_url.format(faceListId,persistedFaceId),headers=headers)#学生填写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_delete_face"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaces': [{'persistedFaceId': '4f7d29aa-3328-4db4-aa99-078ca099f06b',\n",
       "   'userData': 'Tay'},\n",
       "  {'persistedFaceId': 'c0369103-92a9-45da-9360-1032217e2a58',\n",
       "   'userData': 'Blackbear'},\n",
       "  {'persistedFaceId': 'cdab2d9e-a699-4ea8-bfea-f055b9e59efa',\n",
       "   'userData': 'PostMalone'},\n",
       "  {'persistedFaceId': '5183429e-0f90-4f75-8b8a-e75e497f68ef',\n",
       "   'userData': 'ConanGray'},\n",
       "  {'persistedFaceId': '217752cd-2fb2-4f91-a454-8286f9cbb872',\n",
       "   'userData': 'Logic'},\n",
       "  {'persistedFaceId': 'e65041fc-42c4-4f9c-bfa5-964088a7e432',\n",
       "   'userData': 'lany'},\n",
       "  {'persistedFaceId': '00608469-807f-46a5-a203-11610c8944f8',\n",
       "   'userData': 'LewisCapaldi'},\n",
       "  {'persistedFaceId': '27dcf411-1e11-410c-b3a7-755d38ddc758',\n",
       "   'userData': 'Christopher'},\n",
       "  {'persistedFaceId': '3ae39d18-995e-4d3a-ad92-5bddf521d183',\n",
       "   'userData': 'JB'},\n",
       "  {'persistedFaceId': '7b982ff5-cf29-432b-863d-8aa70758eeed',\n",
       "   'userData': 'Blackbear'},\n",
       "  {'persistedFaceId': 'ef692497-e61f-4302-895d-43d850aa12ca',\n",
       "   'userData': 'PostMalone'},\n",
       "  {'persistedFaceId': 'fc594817-b796-458e-86d8-a7aa0171d75c',\n",
       "   'userData': 'ConanGray'},\n",
       "  {'persistedFaceId': 'b0d27b78-2b7e-449a-af9c-a6b906c647fb',\n",
       "   'userData': 'Logic'},\n",
       "  {'persistedFaceId': 'd54ae7ec-858c-4c61-88f3-2086c603e13b',\n",
       "   'userData': 'lany'},\n",
       "  {'persistedFaceId': '4b9d6a82-8dee-46f0-8ddb-aa58c86019d2',\n",
       "   'userData': 'LewisCapaldi'},\n",
       "  {'persistedFaceId': '5d0fd1d0-1130-47e8-a91b-0200e34545c1',\n",
       "   'userData': 'Christopher'}],\n",
       " 'faceListId': 'zy03',\n",
       " 'name': '相册集'}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 检查列表内人脸列表\n",
    "get_face_url =\"https://api-zy.cognitiveservices.azure.com/face/v1.0/facelists/wx02\"\n",
    "r_get_facelist = requests.get(get_facelist_url,headers=headers)\n",
    "r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': 'e1fdeb03-db0f-45c8-be55-422ed3c6f517',\n",
       "  'faceRectangle': {'top': 131, 'left': 251, 'width': 248, 'height': 248},\n",
       "  'faceAttributes': {'smile': 0.0,\n",
       "   'headPose': {'pitch': -5.1, 'roll': 1.9, 'yaw': 3.9},\n",
       "   'gender': 'male',\n",
       "   'age': 27.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.0,\n",
       "    'neutral': 0.999,\n",
       "    'sadness': 0.001,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.03},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.62},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.19},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [{'type': 'headwear', 'confidence': 1.0}],\n",
       "   'occlusion': {'foreheadOccluded': True,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.0, 'invisible': True, 'hairColor': []}}}]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3、检测人脸的id\n",
    "# replace <My Endpoint String> with the string from your endpoint URL\n",
    "face_api_url = 'https://api-zy.cognitiveservices.azure.com/face/v1.0/detect'\n",
    "assert subscription_key\n",
    "\n",
    "# 请求正文\n",
    "image_url = 'https://wx2.sinaimg.cn/mw690/ecff9b1aly1gh1xv6j4lcj20u011h44a.jpg'\n",
    "\n",
    "headers = {'Ocp-Apim-Subscription-Key': subscription_key\n",
    "         }\n",
    "\n",
    "# 请求参数\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    # 选择model\n",
    "    'recognitionModel':'recognition_03',#此参数需与facelist参数一致\n",
    "    'detectionModel':'detection_01',\n",
    "    # 可选参数,请仔细阅读API文档\n",
    "    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',\n",
    "}\n",
    "\n",
    "response = requests.post(face_api_url, params=params,\n",
    "                         headers=headers, json={\"url\": image_url})\n",
    "# json.dumps 将json--->字符串\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "findsimilars_url = \"https://api-zy.cognitiveservices.azure.com/face/v1.0/findsimilars\"\n",
    "\n",
    "# 请求正文 faceId需要先检测一张照片获取\n",
    "data_findsimilars = {\n",
    "    \"faceId\":\"e1fdeb03-db0f-45c8-be55-422ed3c6f517\",#取上方的faceID\n",
    "    \"faceListId\": \"zy03\",\n",
    "    \"maxNumOfCandidatesReturned\": 10,\n",
    "    \"mode\": \"matchFace\"#matchPerson #一种为验证模式，一种为相似值模式\n",
    "    }\n",
    "\n",
    "r_findsimilars = requests.post(findsimilars_url,headers=headers,json=data_findsimilars)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'persistedFaceId': 'c0369103-92a9-45da-9360-1032217e2a58',\n",
       "  'confidence': 1.0},\n",
       " {'persistedFaceId': '7b982ff5-cf29-432b-863d-8aa70758eeed',\n",
       "  'confidence': 1.0},\n",
       " {'persistedFaceId': '217752cd-2fb2-4f91-a454-8286f9cbb872',\n",
       "  'confidence': 0.19634},\n",
       " {'persistedFaceId': 'b0d27b78-2b7e-449a-af9c-a6b906c647fb',\n",
       "  'confidence': 0.19634},\n",
       " {'persistedFaceId': '3ae39d18-995e-4d3a-ad92-5bddf521d183',\n",
       "  'confidence': 0.19118},\n",
       " {'persistedFaceId': 'e65041fc-42c4-4f9c-bfa5-964088a7e432',\n",
       "  'confidence': 0.14233},\n",
       " {'persistedFaceId': 'd54ae7ec-858c-4c61-88f3-2086c603e13b',\n",
       "  'confidence': 0.14233},\n",
       " {'persistedFaceId': '5183429e-0f90-4f75-8b8a-e75e497f68ef',\n",
       "  'confidence': 0.0996},\n",
       " {'persistedFaceId': 'fc594817-b796-458e-86d8-a7aa0171d75c',\n",
       "  'confidence': 0.0996},\n",
       " {'persistedFaceId': 'cdab2d9e-a699-4ea8-bfea-f055b9e59efa',\n",
       "  'confidence': 0.09558}]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_findsimilars.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>4f7d29aa-3328-4db4-aa99-078ca099f06b</td>\n",
       "      <td>Tay</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>c0369103-92a9-45da-9360-1032217e2a58</td>\n",
       "      <td>Blackbear</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>cdab2d9e-a699-4ea8-bfea-f055b9e59efa</td>\n",
       "      <td>PostMalone</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5183429e-0f90-4f75-8b8a-e75e497f68ef</td>\n",
       "      <td>ConanGray</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>217752cd-2fb2-4f91-a454-8286f9cbb872</td>\n",
       "      <td>Logic</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>e65041fc-42c4-4f9c-bfa5-964088a7e432</td>\n",
       "      <td>lany</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>00608469-807f-46a5-a203-11610c8944f8</td>\n",
       "      <td>LewisCapaldi</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>27dcf411-1e11-410c-b3a7-755d38ddc758</td>\n",
       "      <td>Christopher</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>3ae39d18-995e-4d3a-ad92-5bddf521d183</td>\n",
       "      <td>JB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>7b982ff5-cf29-432b-863d-8aa70758eeed</td>\n",
       "      <td>Blackbear</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>ef692497-e61f-4302-895d-43d850aa12ca</td>\n",
       "      <td>PostMalone</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>fc594817-b796-458e-86d8-a7aa0171d75c</td>\n",
       "      <td>ConanGray</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>b0d27b78-2b7e-449a-af9c-a6b906c647fb</td>\n",
       "      <td>Logic</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>d54ae7ec-858c-4c61-88f3-2086c603e13b</td>\n",
       "      <td>lany</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>4b9d6a82-8dee-46f0-8ddb-aa58c86019d2</td>\n",
       "      <td>LewisCapaldi</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>5d0fd1d0-1130-47e8-a91b-0200e34545c1</td>\n",
       "      <td>Christopher</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         persistedFaceId      userData\n",
       "0   4f7d29aa-3328-4db4-aa99-078ca099f06b           Tay\n",
       "1   c0369103-92a9-45da-9360-1032217e2a58     Blackbear\n",
       "2   cdab2d9e-a699-4ea8-bfea-f055b9e59efa    PostMalone\n",
       "3   5183429e-0f90-4f75-8b8a-e75e497f68ef     ConanGray\n",
       "4   217752cd-2fb2-4f91-a454-8286f9cbb872         Logic\n",
       "5   e65041fc-42c4-4f9c-bfa5-964088a7e432          lany\n",
       "6   00608469-807f-46a5-a203-11610c8944f8  LewisCapaldi\n",
       "7   27dcf411-1e11-410c-b3a7-755d38ddc758   Christopher\n",
       "8   3ae39d18-995e-4d3a-ad92-5bddf521d183            JB\n",
       "9   7b982ff5-cf29-432b-863d-8aa70758eeed     Blackbear\n",
       "10  ef692497-e61f-4302-895d-43d850aa12ca    PostMalone\n",
       "11  fc594817-b796-458e-86d8-a7aa0171d75c     ConanGray\n",
       "12  b0d27b78-2b7e-449a-af9c-a6b906c647fb         Logic\n",
       "13  d54ae7ec-858c-4c61-88f3-2086c603e13b          lany\n",
       "14  4b9d6a82-8dee-46f0-8ddb-aa58c86019d2  LewisCapaldi\n",
       "15  5d0fd1d0-1130-47e8-a91b-0200e34545c1   Christopher"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#facelist里面的数据\n",
    "import pandas as pd\n",
    "adf = pd.json_normalize(r_get_facelist.json()[\"persistedFaces\"])# 升级pandas才能运行\n",
    "adf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>c0369103-92a9-45da-9360-1032217e2a58</td>\n",
       "      <td>1.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7b982ff5-cf29-432b-863d-8aa70758eeed</td>\n",
       "      <td>1.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>217752cd-2fb2-4f91-a454-8286f9cbb872</td>\n",
       "      <td>0.19634</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>b0d27b78-2b7e-449a-af9c-a6b906c647fb</td>\n",
       "      <td>0.19634</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3ae39d18-995e-4d3a-ad92-5bddf521d183</td>\n",
       "      <td>0.19118</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>e65041fc-42c4-4f9c-bfa5-964088a7e432</td>\n",
       "      <td>0.14233</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>d54ae7ec-858c-4c61-88f3-2086c603e13b</td>\n",
       "      <td>0.14233</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>5183429e-0f90-4f75-8b8a-e75e497f68ef</td>\n",
       "      <td>0.09960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>fc594817-b796-458e-86d8-a7aa0171d75c</td>\n",
       "      <td>0.09960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>cdab2d9e-a699-4ea8-bfea-f055b9e59efa</td>\n",
       "      <td>0.09558</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId  confidence\n",
       "0  c0369103-92a9-45da-9360-1032217e2a58     1.00000\n",
       "1  7b982ff5-cf29-432b-863d-8aa70758eeed     1.00000\n",
       "2  217752cd-2fb2-4f91-a454-8286f9cbb872     0.19634\n",
       "3  b0d27b78-2b7e-449a-af9c-a6b906c647fb     0.19634\n",
       "4  3ae39d18-995e-4d3a-ad92-5bddf521d183     0.19118\n",
       "5  e65041fc-42c4-4f9c-bfa5-964088a7e432     0.14233\n",
       "6  d54ae7ec-858c-4c61-88f3-2086c603e13b     0.14233\n",
       "7  5183429e-0f90-4f75-8b8a-e75e497f68ef     0.09960\n",
       "8  fc594817-b796-458e-86d8-a7aa0171d75c     0.09960\n",
       "9  cdab2d9e-a699-4ea8-bfea-f055b9e59efa     0.09558"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 返回相似度的数据\n",
    "bdf = pd.json_normalize(r_findsimilars.json())# 升级pandas才能运行\n",
    "bdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>c0369103-92a9-45da-9360-1032217e2a58</td>\n",
       "      <td>Blackbear</td>\n",
       "      <td>1.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7b982ff5-cf29-432b-863d-8aa70758eeed</td>\n",
       "      <td>Blackbear</td>\n",
       "      <td>1.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>217752cd-2fb2-4f91-a454-8286f9cbb872</td>\n",
       "      <td>Logic</td>\n",
       "      <td>0.19634</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>b0d27b78-2b7e-449a-af9c-a6b906c647fb</td>\n",
       "      <td>Logic</td>\n",
       "      <td>0.19634</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>3ae39d18-995e-4d3a-ad92-5bddf521d183</td>\n",
       "      <td>JB</td>\n",
       "      <td>0.19118</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>e65041fc-42c4-4f9c-bfa5-964088a7e432</td>\n",
       "      <td>lany</td>\n",
       "      <td>0.14233</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>d54ae7ec-858c-4c61-88f3-2086c603e13b</td>\n",
       "      <td>lany</td>\n",
       "      <td>0.14233</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5183429e-0f90-4f75-8b8a-e75e497f68ef</td>\n",
       "      <td>ConanGray</td>\n",
       "      <td>0.09960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>fc594817-b796-458e-86d8-a7aa0171d75c</td>\n",
       "      <td>ConanGray</td>\n",
       "      <td>0.09960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>cdab2d9e-a699-4ea8-bfea-f055b9e59efa</td>\n",
       "      <td>PostMalone</td>\n",
       "      <td>0.09558</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId    userData  confidence\n",
       "0  c0369103-92a9-45da-9360-1032217e2a58   Blackbear     1.00000\n",
       "6  7b982ff5-cf29-432b-863d-8aa70758eeed   Blackbear     1.00000\n",
       "3  217752cd-2fb2-4f91-a454-8286f9cbb872       Logic     0.19634\n",
       "8  b0d27b78-2b7e-449a-af9c-a6b906c647fb       Logic     0.19634\n",
       "5  3ae39d18-995e-4d3a-ad92-5bddf521d183          JB     0.19118\n",
       "4  e65041fc-42c4-4f9c-bfa5-964088a7e432        lany     0.14233\n",
       "9  d54ae7ec-858c-4c61-88f3-2086c603e13b        lany     0.14233\n",
       "2  5183429e-0f90-4f75-8b8a-e75e497f68ef   ConanGray     0.09960\n",
       "7  fc594817-b796-458e-86d8-a7aa0171d75c   ConanGray     0.09960\n",
       "1  cdab2d9e-a699-4ea8-bfea-f055b9e59efa  PostMalone     0.09558"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#合并在一起，得出班级能谁最像你\n",
    "pd.merge(adf, bdf,how='inner', on='persistedFaceId').sort_values(by=\"confidence\",ascending = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
